package com.cqs.learning.spring.cloud.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cqs.learning.spring.cloud.app.bean.po.HousePrice;
import com.cqs.learning.spring.cloud.app.bean.vo.ResultMessage;
import com.cqs.learning.spring.cloud.app.service.HousePriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;

/**
 * @Author lixw
 * @Date 7/17/20 7:23 AM
 */
@RestController
@RequestMapping("/hs")
public class HousePriceController {

    @Autowired
    private HousePriceService housePriceService;

    @RequestMapping("/list")
    public ResultMessage list(HousePrice housePrice, @RequestParam(value = "no", defaultValue = "1") int no,
                              @RequestParam(value = "size", defaultValue = "10") int size) {
        QueryWrapper<HousePrice> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(housePrice);
        Page<HousePrice> page = new Page<>();
        page.setPages(no);
        page.setSize(size);
        queryWrapper.orderByDesc("create_time");
        page = housePriceService.page(page, queryWrapper);
        return ResultMessage.builder().date(page).build();
    }

    @RequestMapping("/get/{id}")
    public ResultMessage getById(@PathVariable("id") Long id){
        return ResultMessage.builder().date(housePriceService.getById(id)).build();
    }
}
